

package com.mt.restaurant.controller.sale;

import com.mt.restaurant.dto.sale.MenuMaterialRelationShipHandleDto;
import org.springframework.security.access.prepost.PreAuthorize;
import com.mt.common.core.annotation.ApiPageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mt.common.core.web.base.PageDTO;
import com.mt.common.core.web.base.PageResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



import com.mt.restaurant.dto.sale.MenuMaterialRelationShipEditDto;
import com.mt.restaurant.entity.sale.MenuMaterialRelationShip;
import com.mt.restaurant.service.sale.MenuMaterialRelationShipService;
										

@Api(tags = "菜谱材料关系")
@RestController
@RequestMapping("/api/restaurant/sale/MenuMaterialRelationShip")
@CrossOrigin(allowCredentials = "true")
public class MenuMaterialRelationShipController {
private static Logger logger = LoggerFactory.getLogger(MenuMaterialRelationShipController.class);



																																	@Autowired private MenuMaterialRelationShipService menuMaterialRelationShipService;
	
	/**
	* 根据分页参数查询菜谱材料关系集合
	*
	* @param pageDTO 分页条件
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:MenuMaterialRelationShip:view')")
	@ApiOperation("分页查询菜谱材料关系")
	@ApiPageParam
	@PostMapping("/findMenuMaterialRelationShips")
	public PageResultDTO findMenuMaterialRelationShips(@RequestBody PageDTO pageDTO){
		return this.menuMaterialRelationShipService.findMenuMaterialRelationShips(pageDTO);
	}

	/**
	* 根据ID查询指定的菜谱材料关系
	*
	* @param menuMaterialRelationShipId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:MenuMaterialRelationShip:view')")
	@ApiOperation("根据id查询菜谱材料关系")
	@ApiPageParam
	@PostMapping("/findMenuMaterialRelationShip")
	public MenuMaterialRelationShip findMenuMaterialRelationShip(@RequestParam Long menuMaterialRelationShipId){
		return this.menuMaterialRelationShipService.findMenuMaterialRelationShip(menuMaterialRelationShipId);
	}

	/**
	* 根据ID查询指定的菜谱材料关系(包含外键名称)
	*
	* @param menuMaterialRelationShipId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:MenuMaterialRelationShip:view')")
	@ApiOperation("根据ID查询指定的菜谱材料关系(包含外键名称)")
	@PostMapping("/findMenuMaterialRelationShipForView")
	public MenuMaterialRelationShip findMenuMaterialRelationShipForView(@RequestParam Long menuMaterialRelationShipId){
		return this.menuMaterialRelationShipService.findMenuMaterialRelationShipWithForeignName(menuMaterialRelationShipId);
	}

	/**
	* 根据ID查询指定的菜谱材料关系(包含菜谱材料关系和外键名称)
	*
	* @param menuMaterialRelationShipId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:MenuMaterialRelationShip:view')")
	@ApiOperation("根据ID查询指定的菜谱材料关系(包含菜谱材料关系和外键名称)")
	@PostMapping("/findMenuMaterialRelationShipForEdit")
	public MenuMaterialRelationShipEditDto findMenuMaterialRelationShipForEdit(@RequestParam Long menuMaterialRelationShipId){
				MenuMaterialRelationShipEditDto menuMaterialRelationShipEditDto = new MenuMaterialRelationShipEditDto();
		menuMaterialRelationShipEditDto.setMenuMaterialRelationShip(this.menuMaterialRelationShipService.findMenuMaterialRelationShipWithForeignName(menuMaterialRelationShipId));

		this.prepareMenuMaterialRelationShipEditDto(menuMaterialRelationShipEditDto);

		return menuMaterialRelationShipEditDto;
	}

	/**
	* 根据ID查询指定的菜谱材料关系(只提取ID 和 Name)
	*
	* @param menuMaterialRelationShipId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:MenuMaterialRelationShip:view')")
	@ApiOperation("根据ID查询指定的菜谱材料关系(只提取ID 和 Name)")
	@PostMapping("/findMenuMaterialRelationShipsWithIdNameById")
	public MenuMaterialRelationShip findMenuMaterialRelationShipsWithIdNameById(@RequestParam Long menuMaterialRelationShipId){
	return this.menuMaterialRelationShipService.findMenuMaterialRelationShipsWithIdNameById(menuMaterialRelationShipId);
	}

	/**
	* 根据名称查询菜谱材料关系集合(只提取ID 和 Name)
	*
	* @param menuMaterialRelationShipName 名称
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:MenuMaterialRelationShip:view')")
	@ApiOperation("根据名称查询菜谱材料关系集合(只提取ID 和 Name)")
	@PostMapping("/findMenuMaterialRelationShipsWithIdNameByName")
	public List<MenuMaterialRelationShip> findMenuMaterialRelationShipsWithIdNameByName(@RequestParam String menuMaterialRelationShipName){
	return this.menuMaterialRelationShipService.findMenuMaterialRelationShipsWithIdNameByName(menuMaterialRelationShipName);
	}


	/**
	* 创建新的菜谱材料关系
	*
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:MenuMaterialRelationShip:add')")
	@ApiOperation("创建新的菜谱材料关系")
	@PostMapping("/createMenuMaterialRelationShip")
	public MenuMaterialRelationShipEditDto createMenuMaterialRelationShip(){
				MenuMaterialRelationShipEditDto menuMaterialRelationShipEditDto = new MenuMaterialRelationShipEditDto();
		menuMaterialRelationShipEditDto.setMenuMaterialRelationShip(new MenuMaterialRelationShip());

		this.prepareMenuMaterialRelationShipEditDto(menuMaterialRelationShipEditDto);
		return menuMaterialRelationShipEditDto;
	}

	private void prepareMenuMaterialRelationShipEditDto(MenuMaterialRelationShipEditDto menuMaterialRelationShipEditDto){
																																}

	/**
	* 新增保存菜谱材料关系
	*
	* @param menuMaterialRelationShip 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:MenuMaterialRelationShip:add')")
	@ApiOperation("新增保存菜谱材料关系")
	@PostMapping("/saveMenuMaterialRelationShip")
	public MenuMaterialRelationShip saveMenuMaterialRelationShip(@RequestBody MenuMaterialRelationShip menuMaterialRelationShip){
		return this.menuMaterialRelationShipService.saveMenuMaterialRelationShip(menuMaterialRelationShip);
	}

	/**
	* 修改保存菜谱材料关系
	*
	* @param menuMaterialRelationShip 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:MenuMaterialRelationShip:update')")
	@ApiOperation("修改保存菜谱材料关系")
	@PostMapping("/updateMenuMaterialRelationShip")
	public MenuMaterialRelationShip updateMenuMaterialRelationShip(@RequestBody MenuMaterialRelationShip menuMaterialRelationShip){
		return this.menuMaterialRelationShipService.updateMenuMaterialRelationShip(menuMaterialRelationShip);
	}

	/**
	* 根据ID删除菜谱材料关系
	*
	* @param menuMaterialRelationShipId ID
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:MenuMaterialRelationShip:remove')")
	@ApiOperation("根据ID删除菜谱材料关系")
	@PostMapping("/deleteMenuMaterialRelationShip")
	public void deleteMenuMaterialRelationShip(@RequestParam Long menuMaterialRelationShipId){
		this.menuMaterialRelationShipService.deleteMenuMaterialRelationShip(menuMaterialRelationShipId);
	}


//	@PreAuthorize("hasAuthority('restaurant:sale:MenuMaterialRelationShip:remove')")
	@ApiOperation("批量处理")
	@PostMapping("/batchHandle")
	public void batchHandle(@RequestBody MenuMaterialRelationShipHandleDto menuMaterialRelationShipHandleDto){
		this.menuMaterialRelationShipService.batchHandle(menuMaterialRelationShipHandleDto);
	}


}

